*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Classify occupation-industry pairs into a set of job types.
*-------------------------------------------------------------------------------

capture program drop classify_jobs
program define classify_jobs
	version 15.0
	syntax, [labels_only]

	* Create "job" variable unless user specifies otherwise
	if "`labels_only'" == "" {
		* Ensure requisite variables are present
		confirm variable school ind1990 occ1990

		* Classify non-education jobs
		quietly gen byte job = .
		quietly replace job = 01 if school == 0 & inrange(occ1990, 000, 022)
		quietly replace job = 02 if school == 0 & inrange(occ1990, 023, 037)
		quietly replace job = 03 if school == 0 & inrange(occ1990, 043, 083)
		quietly replace job = 04 if school == 0 & inrange(occ1990, 084, 106)
		quietly replace job = 05 if school == 0 & inrange(occ1990, 113, 163)
		quietly replace job = 06 if school == 0 & (inrange(occ1990, 166, 173) | inrange(occ1990, 178, 179))
		quietly replace job = 07 if school == 0 & (inrange(occ1990, 164, 165) | inrange(occ1990, 174, 176) | inrange(occ1990, 183, 200))
		quietly replace job = 08 if school == 0 & inrange(occ1990, 201, 235)
		quietly replace job = 09 if school == 0 & inrange(occ1990, 243, 243)
		quietly replace job = 10 if school == 0 & inrange(occ1990, 253, 283)
		quietly replace job = 11 if school == 0 & inrange(occ1990, 303, 344)
		quietly replace job = 12 if school == 0 & inrange(occ1990, 345, 389)
		quietly replace job = 13 if school == 0 & (inrange(occ1990, 405, 407) | inrange(occ1990, 448, 455))
		quietly replace job = 14 if school == 0 & inrange(occ1990, 415, 427)
		quietly replace job = 15 if school == 0 & inrange(occ1990, 434, 444)
		quietly replace job = 16 if school == 0 & inrange(occ1990, 445, 447)
		quietly replace job = 17 if school == 0 & inrange(occ1990, 456, 469)
		quietly replace job = 18 if school == 0 & inrange(occ1990, 471, 500)
		quietly replace job = 19 if school == 0 & inrange(occ1990, 501, 549)
		quietly replace job = 20 if school == 0 & inrange(occ1990, 558, 599)
		quietly replace job = 21 if school == 0 & inrange(occ1990, 614, 699)
		quietly replace job = 22 if school == 0 & inrange(occ1990, 703, 799)
		quietly replace job = 23 if school == 0 & inrange(occ1990, 803, 889)

		* Classify education jobs
		quietly replace job = 24 if school == 1 & inrange(occ1990, 155, 156)
		quietly replace job = 25 if school == 1 & inrange(occ1990, 157, 159)
		quietly replace job = 26 if school == 1 & inrange(occ1990, 113, 154)
		quietly replace job = 27 if school == 1 & ind1990 == 842 & missing(job)
		quietly replace job = 28 if school == 1 & ind1990 != 842 & missing(job)
		assert missing(job) == missing(ind1990, occ1990)
	}

	* Label job types
	label define job_lbl 00 "All job types", replace
	label define job_lbl 01 "Executive, administrative, and managerial", add
	label define job_lbl 02 "Management-related", add
	label define job_lbl 03 "Engineers and scientists", add
	label define job_lbl 04 "Health care professionals", add
	label define job_lbl 05 "Teacher (outside education sector)", add
	label define job_lbl 06 "Lawyers and social scientists", add
	label define job_lbl 07 "Other professionals", add
	label define job_lbl 08 "Technologists and technicians", add
	label define job_lbl 09 "Sales supervisors", add
	label define job_lbl 10 "Sales", add
	label define job_lbl 11 "Secretaries and records clerks", add
	label define job_lbl 12 "Other administrative support", add
	label define job_lbl 13 "Cleaning services", add
	label define job_lbl 14 "Protective services", add
	label define job_lbl 15 "Food services", add
	label define job_lbl 16 "Health services", add
	label define job_lbl 17 "Personal services", add
	label define job_lbl 18 "Farming, forestry, and fishing", add
	label define job_lbl 19 "Mechanics and repairers", add
	label define job_lbl 20 "Construction trades", add
	label define job_lbl 21 "Extractive and precision production", add
	label define job_lbl 22 "Machine operators, assemblers, and inspectors", add
	label define job_lbl 23 "Transportation and material moving", add
	label define job_lbl 24 "Ed. services: pre-K/primary school teacher", add
	label define job_lbl 25 "Ed. services: secondary school teacher", add
	label define job_lbl 26 "Ed. services: postsecondary school teacher", add
	label define job_lbl 27 "Ed. services: K-12 non-teaching staff", add
	label define job_lbl 28 "Ed. services: other non-teaching staff", add

	if "`labels_only'" == "" {
		label values job job_lbl
	}
end
